#ifndef REAL_TIME_OUTLIER_REMOVAL_H
#define REAL_TIME_OUTLIER_REMOVAL_H

#include <cmath>

class RealTimeOutlierRemoval {
public:
    RealTimeOutlierRemoval(double threshold = 3.0)
        : threshold_(threshold), mean_(0.0), stdev_(0.0), count_(0), last_valid_value_(0.0) {}

    // 更新并判断当前数据点是否是异常值
    double process(double new_value);

    // 获取当前的均值
    double getMean() const { return mean_; }

    // 获取当前的标准差
    double getStdDev() const { return count_ > 1 ? std::sqrt(stdev_ / (count_ - 1)) : 0.0; }

private:
    double threshold_; // 异常值剔除的阈值（倍数）
    double mean_;      // 当前的均值
    double stdev_;     // 当前的标准差
    size_t count_;     // 数据点的数量
    double last_valid_value_;
};

#endif // REAL_TIME_OUTLIER_REMOVAL_H